
*********************************************************************************************;

/* 						 This file reproduce Table 11: GIV results							*/

*********************************************************************************************;


libname rep "C:\Users\~";

data regbase; set rep.mydata; run;

proc standard data = regbase mean=0 std =1 out = zvars;
var syy_low syy_high gmf_ts_low gmf_ts_high ghf_ts_low ghf_ts_high gmf_cs_low gmf_cs_high ghf_cs_low ghf_cs_high 
eta1_mh eta2_mh eta1_ex eta2_ex pc1_mh pc2_mh pc1_ex pc2_ex gdp mktrf amihud tover hml smb; run;

*** regressions using GIV ***;

option missing = " ";
%macro print;
data N; set N; Estimate = nValue1; if Label1 = "Used"; run;
data Nobs; set N; Parameter = "N"; keep EstType Parameter Estimate; run;
data r2; set fit; Parameter = "RSQ"; keep EstType Parameter RSquare; rename RSquare = Estimate;  run;
data final; set parest Nobs r2 ; drop EstType StdErr Probt DF; run;
data final&i; set final; rename Estimate = &type._&freq tValue = t_&type._&freq; 
if Parameter not in ("h_freq", "a_freq", "e1", "e2", "e3", "e4", "f1", "f2", "f3", "f4", "N", "RSQ") then delete; run;
%mend;


%macro decomp ;

%do j=1 %to 2;

%if &j =1 %then %do; %let type = ts; %end; 
%else %do; %let type = cs; %end;

%do i=1 %to 2;
%if &i =1 %then %do; %let freq = low; %let con = high; %end; 
%else %do; %let freq = high; %let con = low; %end;

ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=zvars plot =none;
endo syy_&freq ; 
exog gmf_&type._low gmf_&type._high ghf_&type._low ghf_&type._high eta1_mh eta2_mh eta1_ex eta2_ex pc1_mh pc2_mh pc1_ex pc2_ex gdp mktrf amihud tover hml smb; instruments _exog_;
syy_&freq =z0 + h_freq* ghf_&type._&freq +h_con* ghf_&type._&con + a_freq*gmf_&type._&freq + a_con*gmf_&type._&con +e1*eta1_mh + e2*eta2_mh +e3*eta1_ex + e4*eta2_ex 
+f1*pc1_mh + f2*pc2_mh +f3*pc1_ex + f4*pc2_ex + g*gdp +k1*mktrf +k2*amihud +k3*tover +k4*hml +k5*smb; ;
fit syy_&freq / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;

data &type; merge final1 final2; run;
%end;
data T11; merge ts cs; run;

%mend;

%decomp;

proc print data = T11; run;
